import socket

url = 'https://gimg2.baidu.com/image_search/src=http%3A%2F%2F117.img.pp.sohu.com%2Fimages%2Fblog%2F2007%2F4%2F30%2F8%2F13%2F112d7b0383b.jpg&refer=http%3A%2F%2F117.img.pp.sohu.com&app=2002&size=f9999,10000&q=a80&n=0&g=0n&fmt=jpeg?sec=1629683322&t=8abf3cab27086533a96c6e4f20160ad7'
#
# client = socket.socket()
# client.connect(('gimg2.baidu.com',80))

# req = 'GET /image_search/src=http%3A%2F%2F117.img.pp.sohu.com%2Fimages%2Fblog%2F2007%2F4%2F30%2F8%2F13%2F112d7b0383b.jpg&refer=http%3A%2F%2F117.img.pp.sohu.com&app=2002&size=f9999,10000&q=a80&n=0&g=0n&fmt=jpeg?sec=1629683322&t=8abf3cab27086533a96c6e4f20160ad7 HTTP/1.0\r\nHOST:gimg2.baidu.com\r\n\r\n'

# client.send(req.encode())
# data = client.recv(1024)
#
# import re
# res = b''
# while data:
#     res += data
#     data = client.recv(1024)
#
# content = re.findall(b'\r\n\r\n(.*)',res,re.S)
# with open('meim.jpg','wb') as f:
#     f.write(content[0])


# client = socket.socket()
# client.connect(('gimg2.baidu.com',80))
# # req = 'GET / img2/../../.. HTTP/1.0\r\nHOST:baidu.com\r\n\r\n')
# client.send(req.encode())
# data = client.recv(1024)
#
# res = b''
# while data:
#     res +=data
#     data = client.recv(1024)
# import re
#
# content = re.findall(b'\r\n\r\n(.*)',res,re.S)
#
# with open('mm.jpg','wb') as f:
#     f.write(content[0])



# import socket
#
# client = socket.socket()
# client.connect(('gimg2.baidu.com',80))
#
# req = 'GET /image_search/src=http%3A%2F%2F117.img.pp.sohu.com%2Fimages%2Fblog%2F2007%2F4%2F30%2F8%2F13%2F112d7b0383b.jpg&refer=http%3A%2F%2F117.img.pp.sohu.com&app=2002&size=f9999,10000&q=a80&n=0&g=0n&fmt=jpeg?sec=1629683322&t=8abf3cab27086533a96c6e4f20160ad7  HTTP/1.0\r\nHOST:gimg2.baidu.com\r\n\r\n'
#
# client.send(req.encode())
#
# data = client.recv(1024)
# # print(data)
# res = b''
# while data:
#     res +=data
#     data=client.recv(1024)
#
# import re
# content = re.findall(b'\r\n\r\n(.*)',res,re.S)
#
# with open('mm1.jpg','wb')as f:
#     f.write(content[0])

# import socket
#
# url = 'https://gimg2.baidu.com/image_search/src=http%3A%2F%2Fdingyue.ws.126.net%2FmvfSUt0Ofl5F4awiwlygoyHyolR1QqOadrqcK3GdoF42g1585473147787compressflag.jpeg&refer=http%3A%2F%2Fdingyue.ws.126.net&app=2002&size=f9999,10000&q=a80&n=0&g=0n&fmt=jpeg?sec=1629851581&t=da1b6fedefe17450240b6968a007d09e'
# client = socket.socket()
# client.connect(('gimg2.baidu.com',80))
#
# req = 'GET /image_search/src=http%3A%2F%2Fpic1.win4000.com%2Fwallpaper%2F2020-04-14%2F5e95539df2ade.jpg&refer=http%3A%2F%2Fpic1.win4000.com&app=2002&size=f9999,10000&q=a80&n=0&g=0n&fmt=jpeg?sec=1629851581&t=64e3b3614fcd57b8c9ce38eafdadd819 HTTP/1.0\r\nHOST:gimg2.baidu.com\r\n\r\n'
#
# client.send(req.encode())
# data = client.recv(1024)
# print(data)
# res = b''
# while data:
#     res +=data
#     data=client.recv(1024)
# # print(res)
# # import re
# # comtent = re.findall(b'\r\n\r\n(.*)',res,re.S)
# head,content = res.split(b'\r\n\r\n')
# # print(content)
# with open('biaoqing.jpg','wb')as f:
#     f.write(content)



# 爬网页
import socket
client = socket.socket()
client.connect(('pic.netbian.com/4kmeinv/index_2.html',80))
req = 'GET /4kmeinv/index_2.html HTTP/1.0\r\nHOST:pic.netbian.com\r\n\r\n'
# print(req)
client.send(req.encode())
resp = client.recv(1024)
# print(resp)
res =b''
while resp:
    res +=resp
    resp = client.recv(1024)
print(res.decode('utf8'))
head,body = res.split(b'\r\n\r\n')
html = body.decode('gbk')
# print(html)
with open('baidu10.html',mode='wt',encoding='utf8')as f:
    f.write(html)

